
#import "LocalNotice.h"

@implementation LocalNotice

//设置称重通知
+ (void)setColock:(NSDate*)date
{
    //创建一个新的测量体温推送
    UILocalNotification *notification=[[UILocalNotification alloc] init];
    if (notification!=nil)
    {
        notification.fireDate = date;
        notification.timeZone=[NSTimeZone defaultTimeZone];
        notification.repeatInterval = NSDayCalendarUnit;
        notification.alertBody = @"称重的时间到了";
        notification.soundName = UILocalNotificationDefaultSoundName;
        //设置标志
        NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"称重提醒" forKey:@"key"];
        notification.userInfo = infoDic;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    }
}

//取消称重推送
+ (void)cancelClolck
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    //先删除原有本地推送
    NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"称重提醒" forKey:@"key"];
    [self deleteRemindTime:infoDic];
}

//设置提醒闹钟
+ (void)setRemindTime:(NSDictionary *)dic
{
//    UILocalNotification *noti=[[UILocalNotification alloc] init];
//    if (noti!=nil)
//    {
//        NSDate *date = [CommUtls dencodeTime:[dic valueForKey:TABLE_TX_RemindTime] format:@"yyyy-MM-dd HH:mm"];
//
//        if (noti) {
//            //设置推送时间
//            noti.fireDate = date;
//            //设置时区
//            noti.timeZone = [NSTimeZone defaultTimeZone];
////            //设置重复间隔
////            noti.repeatInterval = NSYearCalendarUnit;
//            //推送声音
//            noti.soundName = UILocalNotificationDefaultSoundName;
//            //内容
//            noti.alertBody = [dic valueForKey:TABLE_TX_RemindContent];
//            //显示在icon上的红色圈中的数子
////            noti.applicationIconBadgeNumber = 1;
//            //设置userinfo 方便在之后需要撤销的时候使用
//            CLog(@"===%@",[dic valueForKey:TABLE_TX_RecordTime]);
//            NSDictionary *infoDic = [NSDictionary dictionaryWithObject:[dic valueForKey:TABLE_TX_RecordTime] forKey:@"key"];
//            noti.userInfo = infoDic;
//            //添加推送到uiapplication
//            UIApplication *app = [UIApplication sharedApplication];
//            [app scheduleLocalNotification:noti];  
//        }
//    }
}

//删除提醒闹钟
+ (void)deleteRemindTime:(NSDictionary *)dic
{
//    UIApplication *app = [UIApplication sharedApplication];
//    //获取本地推送数组
//    NSArray *localArr = [app scheduledLocalNotifications];
//    
//    if (localArr) {
//        for (UILocalNotification *noti in localArr) {
//            NSDictionary *dict = noti.userInfo;
//            if (dict) {
//                NSString *inKey = [dict objectForKey:@"key"];
//                if ([inKey isEqualToString:[dic valueForKey:TABLE_TX_RecordTime]]) {
//                    [app cancelLocalNotification:noti];
//                    CLog(@"删除成功");
//                    break;
//                }
//            }
//        }
//    }
}

@end
